package practice_0526;

public class practice02 {
    public static void main(String[] args) throws InterruptedException {
        Person person = new Person();
        Thread thread = new Thread(person);
        thread.start();
        for (int i = 0; i <5 ; i++) {
            System.out.println(Thread.currentThread().getName()+ i);
            Thread.sleep(500);
        }
//        thread.interrupt();
        person.setLoop(false);

    }
}

class Person implements Runnable{
    boolean loop = true;
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "正在执行");
        int count = 0;

       while(loop) {
           try {
               System.out.println("老韩吃了" + (count++) + "个包子");
               Thread.sleep(50);
           } catch (InterruptedException e) {
               throw new RuntimeException(e);
           }

       }
    }

    public void setLoop(boolean loop) {
        this.loop = loop;
    }
}
